/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cse308.helper_classes;

import cse308.General;
import cse308.GeneralEntity;
import cse308.entities.Degreeprogram;
import cse308.entities.Users;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author dwysocki
 */
public class UserClass implements GeneralTest {

    private String firstName;
    private String lastName;
    private String username;
    private String password;
    private String email;
    private Boolean cicMember;
    private Boolean evaluator;
    private Map<String, String> degreePrograms;
    
    private List<String> allDegreePrograms = new ArrayList();
    private List<String> ownDegreePrograms = new ArrayList();
    private Map<String, GeneralTest> degreeProgramMap;
    
    private Boolean editable = false;

    public boolean isEditable() {
        return editable;
    }

    public void setEditable(Boolean editable) {
        this.editable = editable;
    }

    public UserClass(Users entity) {
        this.firstName = entity.getFirstName();
        this.lastName = entity.getLastName();
        this.username = entity.getUsername();
        this.password = entity.getPassword();
        this.email = entity.getEmail();
        this.cicMember = entity.getCicMember();
        this.evaluator = entity.getEvaluator();
        this.degreeProgramMap = new HashMap();
        this.degreePrograms = new HashMap();
        for(Degreeprogram dp : entity.getDegreeprogramCollection()){
            degreePrograms.put(dp.getIdentifier(), dp.getIdentifier());
        }
    }

    @Override
    public String toString() {
        return username;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Boolean getCicMember() {
        return cicMember;
    }

    public void setCicMember(Boolean cicMember) {
        this.cicMember = cicMember;
    }

    public Boolean getEvaluator() {
        return evaluator;
    }

    public void setEvaluator(Boolean evaluator) {
        this.evaluator = evaluator;
    }

    public Map<String, String> getDegreePrograms() {
        return degreePrograms;
    }

    public void setDegreePrograms(Map<String, String> degreePrograms) {
        this.degreePrograms = degreePrograms;
    }

    public List<String> getAllDegreePrograms() {
        return allDegreePrograms;
    }

    public void setAllDegreePrograms(List<String> allDegreePrograms) {
        this.allDegreePrograms = allDegreePrograms;
    }

    public List<String> getOwnDegreePrograms() {
        return ownDegreePrograms;
    }

    public void setOwnDegreePrograms(List<String> ownDegreePrograms) {
        this.ownDegreePrograms = ownDegreePrograms;
    }

    public Map<String, GeneralTest> getDegreeProgramMap() {
        return degreeProgramMap;
    }

    public void setDegreeProgramMap(Map<String, GeneralTest> degreeProgramMap) {
        this.degreeProgramMap = degreeProgramMap;
    }

    public void addDegreeProgramMap(String degreeProgramString, DegreeProgramClass dpc) {
        this.degreeProgramMap.put(degreeProgramString, dpc);
    }

    @Override
    public String getIdentifier2() {
        return this.username;
    }

    @Override
    public ArrayList<Map<String, General>> getMap() {
        ArrayList<Map<String, General>> alMaps = new ArrayList();
        alMaps.add((Map)this.degreeProgramMap);
        return alMaps;
    }

    @Override
    public ArrayList<List<String>> getList() {
        ArrayList<List<String>> al = new ArrayList();
        al.add(this.ownDegreePrograms);
        return al;
    }

    @Override
    public GeneralEntity findCorrespondingEntity() {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("CSE_308_ABETPU");
        EntityManager em = emf.createEntityManager();
        return em.find(Users.class, this.username);
    }

    @Override
    public boolean equalsEntity(GeneralEntity toEqual) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

   // @Override
    public void updateRelationship(GeneralEntity ge1) {
        //Degreeprogram
        if(ge1 instanceof Degreeprogram){
            ((Users)this.findCorrespondingEntity()).getDegreeprogramCollection().add((Degreeprogram)ge1);
        }
    }
}
